import modelExtend from '@/utils/modelExtend';
import HttpModel from '@/models/http';
import { doPostToObj } from '@/services/http';

let dataFieldManagement = {
  namespace: 'serviceCapabilityManagement',
  effects: {
    *postFetchPage({ payload, callback }, { call, put }) {
      const initParams = Object.assign(
        {
          current: 1,
          pageSize: 10,
        },
        payload,
      );
      const response = yield call(doPostToObj, { ...initParams, ...payload });
      if (response.statusCode === '0') {
        const { data = {} } = response;
        const pageData = {
          list: data?.records ?? [],
          pagination: {
            total: data?.total ?? 0,
            current: data?.current,
            pageSize: data?.size ?? 10,
          },
        };
        yield put({ type: 'req', payload: { pageData: pageData } });
        if (callback) callback(response);
        return response;
      }
    },
  },
};
dataFieldManagement = modelExtend(HttpModel, dataFieldManagement);
export default dataFieldManagement;
